********************************************************************************************************************************
***   Replication file for:                                                                                                  ***
***   Berbee, P., Braun, S. T. and Franke, R. (2024). Reversing Fortunes of German Regions, 1926-2019.					     ***
***	  Journal of Economic Growth                                                                                             ***
***   							                                                                                             ***
***   ---   Main Do-File   ---                                                                                               ***
***
***   Software:
***   Analyses run on Windows using Stata version 16 
***
***   Notes: 
***	  Data are stored in /data
***   Tables are outputted to /results/tables
***   Figures are outputted to /results/figures
***   To perform, a clean run delete the following folders: /results, /processed
***
***
********************************************************************************************************************************

*********************************
***   Set directory   		  ***
*********************************

*** Users must define global macro to point to the folder that contains the main do file
global reversing ""

* Confirm that the global for the project root directory was defined
assert !missing("$reversing")

* Initialize log
clear
set more off
cap mkdir "$reversing/scripts/logs"
cap log close
local datetime : di %tcCCYY.NN.DD!-HH.MM.SS `=clock("$S_DATE $S_TIME", "DMYhms")'
local logfile "$reversing/scripts/logs/`datetime'.log.txt"
log using "`logfile'", text

* Configure Stata's library environment and record system parameters
run "$reversing/scripts/programs/_config.do"

* Stata version control
version 16.1

* Create directories for output files
cap mkdir "$reversing/results"
cap mkdir "$reversing/results/figures"
cap mkdir "$reversing/results/tables"
cap mkdir "$reversing/processed"
cap mkdir "$reversing/processed/intermediate"

* Run project analysis
do "$reversing/scripts/0_data_preparation.do" 
do "$reversing/scripts/1_introduction.do"	  
do "$reversing/scripts/2_data.do" 
do "$reversing/scripts/3_industrialization_and_development.do" 
do "$reversing/scripts/3b_industrialization_and_development_rb.do" 
do "$reversing/scripts/4_lopsided_economic_structure.do"
do "$reversing/scripts/5_reversal_inequality.do"


* End log
di "End date and time: $S_DATE $S_TIME"
log close

exit